<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 3, 2, 4];
            // arr.sort((a, b) => b - a);
            // console.log(arr); // [4,3,2,1]
            Array.prototype.mySort = function (callback) {
                // 使用了冒泡排序
                for (let i = 0; i < this.length - 1; i++) {
                    for (let j = 0; j < this.length - 1 - i; j++) {
                        if (callback(this[j], this[j + 1]) > 0) {
                            let temp = this[j];
                            this[j] = this[j + 1];
                            this[j + 1] = temp;
                        }
                    }
                    return this;
                }
            };
            arr.mySort((a, b) => a - b);
            console.log(arr);
        </script>
    </body>
</html>
